package com.learn.configuration;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.exception.ZuulException;
import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants;
import org.springframework.stereotype.Component;

@Component
public class ZuulFilterConfiguration extends ZuulFilter {
    /**
     * 过滤类型
     */
    @Override
    public String filterType() {
        return FilterConstants.PRE_TYPE;
    }
    
    /**
     * 过滤器优先级，数字越小优先级越高
     */
    @Override
    public int filterOrder() {
        return 0;
    }
    
    /**
     * 是否启用过滤器
     */
    @Override
    public boolean shouldFilter() {
        return true;
    }
    
    /**
     * 过滤器逻辑
     */
    @Override
    public Object run() throws ZuulException {
        // 获取当前请求的上下文
        // RequestContext currentContext = RequestContext.getCurrentContext();
        // 认证原始信息
        // String auth = "product:a";
        // 加密处理
        // byte[] encodeAuth = Base64.getEncoder().encode(auth.getBytes(Charset.forName("US-ASCII")));
        // String authHeader = "Basic" + new String(encodeAuth);
        // 敏感头 过滤
        // currentContext.addOriginResponseHeader("Authorization", authHeader);
        System.out.println("zuul过滤器");
        return null;
    }
}
